class iGameInventoryManager extends InventoryManager;

/** Holds the last weapon used */
var Weapon              PreviousWeapon;

function Inventory CreateInventoryFromTemplate(Actor InventoryActorTemplate, optional bool bDoNotActivate)
{
	local Inventory	Inv;

	if( InventoryActorTemplate != None )
	{
		inv = Inventory(Spawn(InventoryActorTemplate.Class, Owner,,,,InventoryActorTemplate,true));

		if( inv != None )
		{
			if( !AddInventory(Inv, bDoNotActivate) )
			{
				`warn("InventoryManager::CreateInventory - Couldn't Add newly created inventory" @ Inv);
				Inv.Destroy();
				Inv = None;
			}
		}
		else
		{
			`warn("InventoryManager::CreateInventory - Couldn't spawn inventory" @ InventoryActorTemplate);
		}
	}

	return Inv;
}

function GetWeaponList(out array<iGameWeapon> WeaponList, optional bool bNoEmpty)
{
	local iGameWeapon lWeapon;

	ForEach InventoryActors( class'iGameWeapon', lWeapon )
	{
		if ( !bNoEmpty || lWeapon.HasAnyAmmo())
		{
                WeaponList.Insert(0,1);
				WeaponList[0] = lWeapon;
		}
	}
}

simulated function Inventory CreateInventory(class<Inventory> NewInventoryItemClass, optional bool bDoNotActivate)
{
	if (Role==ROLE_Authority)
	{
		return Super.CreateInventory(NewInventoryItemClass, bDoNotActivate);
	}
	return none;
}

/**
 * Handle AutoSwitching to a weapon
 */
simulated function bool AddInventory( Inventory NewItem, optional bool bDoNotActivate )
{
	local bool bResult;

	if (Role == ROLE_Authority)
	{
		bResult = super.AddInventory(NewItem, bDoNotActivate);
	}
	return bResult;
}

simulated function RemoveFromInventory(Inventory ItemToRemove)
{
	if (Role==ROLE_Authority)
	{
		Super.RemoveFromInventory(ItemToRemove);
	}
}

/**
 * Scans the inventory looking for any of type InvClass.  If it finds it it returns it, other
 * it returns none.
 */
function Inventory HasInventoryOfClass(class<Inventory> InvClass)
{
	local inventory inv;

	inv = InventoryChain;
	while(inv!=none)
	{
		if (Inv.Class==InvClass)
			return Inv;

		Inv = Inv.Inventory;
	}
	return none;
}

/**
 * Store the last used weapon for later
 */
simulated function ChangedWeapon()
{
	PreviousWeapon = Instigator.Weapon;
	Super.ChangedWeapon();
}

function SwitchToPreviousWeapon()
{
	if ( PreviousWeapon!=none && PreviousWeapon != Pawn(Owner).Weapon )
	{
		PreviousWeapon.ClientWeaponSet(false);
	}
}

Defaultproperties
{
	bMustHoldWeapon=true
	PendingFire(0)=0
	PendingFire(1)=0
}
